// Copyright (c) .NET Foundation and Contributors. All Rights Reserved. Licensed under the MIT License (MIT). See License.md in the repository root for more information.

using System;
using System.Collections.Generic;
using ClangSharp.Interop;
using static ClangSharp.Interop.CXCursorKind;
using static ClangSharp.Interop.CX_StmtClass;

namespace ClangSharp;

public sealed class OffsetOfExpr : Expr
{
    private readonly LazyList<Expr, Stmt> _indexExprs;
    private readonly ValueLazy<Cursor?> _referenced;
    private readonly ValueLazy<Type> _typeSourceInfoType;

    internal OffsetOfExpr(CXCursor handle) : base(handle, CXCursor_UnexposedExpr, CX_StmtClass_OffsetOfExpr)
    {
        _indexExprs = LazyList.Create<Expr, Stmt>(_children);
        _referenced = new ValueLazy<Cursor?>(() => !Handle.Referenced.IsNull ? TranslationUnit.GetOrCreate<Cursor>(Handle.Referenced) : null);
        _typeSourceInfoType = new ValueLazy<Type>(() => TranslationUnit.GetOrCreate<Type>(Handle.TypeOperand));
    }

    public IReadOnlyList<Expr> IndexExprs => _indexExprs;

    public uint NumExpressions => NumChildren;

    public Cursor? Referenced => _referenced.Value;

    public Type TypeSourceInfoType => _typeSourceInfoType.Value;
}
